package org.ifdb.controller;

import javax.servlet.http.HttpServletRequest;

import org.ifdb.model.UploadItem;
import org.ifdb.persistency.entity.Country;
import org.ifdb.service.GuestbookService;
import org.ifdb.service.UploadService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.ui.Model;

import com.google.appengine.api.users.UserService;


@Controller
public class UploadController {
	
    private final UploadService uploadService;
    
    @Autowired
    public UploadController(UploadService uploadService) {
        this.uploadService =  uploadService;;
    }
	
	
	@RequestMapping(value = "/uploadForm.do", method = RequestMethod.GET)
	public String getUploadForm(Model model) {
		model.addAttribute(new UploadItem());
		return "uploadForm";
	}
	@RequestMapping(value = "/uploadForm.do", method = RequestMethod.POST)
	public @ResponseBody String postUpload (UploadItem upload, HttpServletRequest request) {
	    if (true) {
	        if (upload.getFile().getSize() != 0) {
	        	uploadService.loadData(upload);
	    		
	            return "uploadForm";
	        }
	    }
	    return "uploadForm";
	}
	
}
